package bpm.domain.document;

import java.io.Serializable;
import java.util.List;

import bpm.domain.process.Node;

/**
 * 
 * @author <a mailto="hwangsyin@gmail.com">King</a>
 *
 */
public class LabelNodeConstraintView implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public Integer id;
	public Integer documentDefinitionId;
	public Integer labelId;
	public String labelKey;
	public String processDefinitionId;
	public String nodeId;
	public String nodeType;
	public String nodeName;
	public String nodeReference;
	public String description;
	public Integer writeFormat;
	public boolean isDefined = false;
	
	public LabelNodeConstraintView() {}
	public LabelNodeConstraintView(Node n, List<FieldConstraint> fcs) {
		if(n != null) {
			this.nodeId = n.getId();
			if(n.getType() != null) {
				this.nodeType = n.getType().name();
			}
			this.nodeName = n.getName();
			this.nodeReference = n.getReference();
			for(FieldConstraint fc : fcs) {
				if(n.getId().equals(fc.getNodeId())) {
					this.id = fc.getId();
					this.documentDefinitionId = fc.getDocumentDefinitionId();
					this.labelId = fc.getFieldId();
					this.processDefinitionId = fc.getProcessDefinitionId();
					this.description = fc.getDescription();
					this.writeFormat = fc.getWriteFormat();
					this.isDefined = true;
					
					break;
				}
			}
		}
	}
	public LabelNodeConstraintView(FieldConstraint constraint){
		this.id=constraint.getId();
		this.documentDefinitionId=constraint.getDocumentDefinitionId();
		this.labelId=constraint.getFieldId();
		this.processDefinitionId = constraint.getProcessDefinitionId();
		this.description = constraint.getDescription();
		this.writeFormat = constraint.getWriteFormat();
		this.isDefined = true;
	}
}
